package com.hotel.domain.service.impl;

import com.github.pagehelper.PageHelper;
import com.hotel.common.PageEntity;
import com.hotel.domain.dao.RoomTypeMapper;
import com.hotel.domain.service.RoomTypeService;
import com.hotel.pojo.RecordInfo;
import com.hotel.pojo.RoomType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class RoomTypeImpl implements RoomTypeService {

    @Autowired
    private RoomTypeMapper roomTypeMapper;

    @Override
    @Transactional
    public int addRoomType(RoomType roomType) {
        return roomTypeMapper.addRoomType(roomType);
    }

    @Override
    @Transactional
    public int updateRoomType(RoomType roomType) {
        return roomTypeMapper.updateRoomType(roomType);
    }

    @Override
    @Transactional
    public PageEntity<RoomType> getRoomTypeList(RoomType roomType, int page, int perPage) {
        PageHelper.startPage(page,perPage);
        //获取列表
        List<RoomType> list = roomTypeMapper.getRoomTypeList(roomType);
        //获得页数
        int pageTotal = (int)Math.ceil(roomTypeMapper.getRoomTypeNum(roomType)/(double)perPage);
        return new PageEntity<RoomType>(list, page, pageTotal);
    }

    @Override
    public List<RoomType> getAllRoomType() {
        return roomTypeMapper.getRoomTypeList(new RoomType());
    }

}
